package com.itheima.HandlerInterceptorAdapter;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Method;

/**
 * @author zhanliuzhu
 * @date 2023/11/11
 * @Description
 */

/**
 * 拦截器
 */
@Component
public class handlerinterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("拦截器拦截到了请求");
        String method = request.getMethod();
        Class<?> aClass = handler.getClass();
        //Method classMethod = aClass.getMethod("getById");
        String simpleName = aClass.getSimpleName();
        ClassLoader classLoader = aClass.getClassLoader();
        Method[] methods = aClass.getMethods();
        System.out.println("nn");
        System.out.println("我的handler："+handler.toString());
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}
